// /**
//  Created by:
//  muhtearjan mehmood مۇختەرجان مەخمۇت (Email: yeganaaa@163.com)
//  At 8/28/20 8:48 PM
//  */
// import * as Http from "http"
// import WebSocket from "ws";
// import {WebSocketBridgeHost, WebSocketServerHost} from "./WebSocketBrodgeHost";
// import {BridgeHostEvents, ServerHostEvents} from "dream_rpc";

// async function main() {
//     const server = Http.createServer()
//     server.listen(44444)

//     const serverHost = new WebSocketServerHost(async () => new WebSocket.Server({
//         server: server,
//         path: "/WebSocket"
//     }))
//     await serverHost.prepare(new ServerHostEvents(
//         async () => {
//             console.log("Server is ready")
//         },
//         async bridge => {
//             console.log("Client connected")
//             await bridge.prepare(new BridgeHostEvents(
//                 async () => {
//                     console.log("Client is now ready.")
//                 },
//                 async error => {
//                     console.log(error)
//                 },
//                 async () => {
//                     console.log("Client closed")
//                 },
//                 async data => {
//                     await bridge.send(data)
//                     console.log(data)
//                 }
//             ))
//             await bridge.open()
//         },
//         async error => {
//             console.log(error)
//         },
//         async () => {
//             console.log("Server is now shutting down...")
//         }
//     ))
//     await serverHost.launch()

//     const client = new WebSocketBridgeHost((async () => new WebSocket("ws://0.0.0.0:44444/WebSocket")))
//     await client.prepare(new BridgeHostEvents(
//         async () => {
//             console.log("CCC is ready")
//             client.send(new TextEncoder().encode("Hello world"))
//         },
//         async error => {},
//         async () => {},
//         async data => {
//             console.log(data)
//         },
//     ))
//     await client.open()

// }

// main()